<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0039)http://www.mrpt.org/book/export/html/39 -->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    
    <title>Compiling MRPT</title>
    <!--<base href="http://www.mrpt.org">--><base href=".">
    <link type="text/css" rel="stylesheet" href="./Compiling MRPT_files/print.css">
      </head>
  <body>
              <div class="section-1">
                <div class="section-2">
                <div class="section-3">
          
    <div id="node-39" class="section-4">
  <h1 class="book-heading">Compiling MRPT</h1>
  
<script type="text/javascript">toc_collapse=0;</script><div class="toc" id="toc">
<div class="toc-title">Table of contents<span class="toc-toggle-message">&nbsp;</span></div>
<div class="toc-list">
<ul>
	<li class="toc-level-1"><a href="http://www.mrpt.org/#Prerequisites">1. Prerequisites</a>
<ul>
	<li class="toc-level-2"><a href="http://www.mrpt.org/#On_Windows">1.1. On Windows</a></li>
	<li class="toc-level-2"><a href="http://www.mrpt.org/#On_GNULinux">1.2. On GNU/Linux</a></li>
	<li class="toc-level-2"><a href="http://www.mrpt.org/#On_Mac">1.3. On Mac</a></li>
</ul>
</li>
	<li class="toc-level-1"><a href="http://www.mrpt.org/#CMake_build_options">2. CMake build options</a>
<ul>
	<li class="toc-level-2"><a href="http://www.mrpt.org/#Using_cmake-gui">2.1. Using cmake-gui</a></li>
	<li class="toc-level-2"><a href="http://www.mrpt.org/#Using_cmake_from_the_console">2.2. Using cmake from the console</a></li>
	<li class="toc-level-2"><a href="http://www.mrpt.org/#Interesting_build_options">2.3. Interesting build options</a></li>
</ul>
</li>
	<li class="toc-level-1"><a href="http://www.mrpt.org/#Generate_MakefilesIDE_Projects">3. Generate Makefiles/IDE Projects</a></li>
	<li class="toc-level-1"><a href="http://www.mrpt.org/#Compile">4. Compile</a></li>
	<li class="toc-level-1"><a href="http://www.mrpt.org/#Special_instructions_for_MinGW">5. Special instructions for MinGW</a></li>
</ul>
</div>
</div>

This page describes how to <b>build MRPT from sources</b>. If you want instead to install the binaries and getting quickly into developing your MRPT-based applications, go to the <a href="http://www.mrpt.org/download">download page</a> and grab the <b>binaries for your system</b>.

Please, report <b>errors or doubts</b> on MRPT compilation to the <a href="http://www.mrpt.org/forum-users">mrpt-users forum</a>.


<br><br>
<br><hr><div style="background-color:#C0C0C0">
<h2 id="Prerequisites">1. Prerequisites</h2>
</div><hr>


<br>
<br><hr><div style="background-color:#F0F0F0">
<h3 id="On_Windows">1.1. On Windows</h3>
</div><hr>


<div style="float: right;"><img src="./Compiling MRPT_files/icon_win.png"></div>
<br>

<h4 id="CMake_Mandatory"> 1.1.1 CMake (Mandatory)</h4>
<br>

To install the CMake build system, follow the instructions at <a href="http://www.cmake.org/cmake/resources/software.html">http://www.cmake.org/cmake/resources/software.html</a>

<br>

<br>
<h4 id="wxWidgets_Optional_but_recommended"> 1.1.2 wxWidgets  (Optional, but recommended)</h4>
<br>

In addition to the following notes, read the project's wiki: <a href="http://wiki.wxwidgets.org/MSVC">http://wiki.wxwidgets.org/MSVC</a>

Also, if you want to build for 64bit (x64), be aware of the limited support of wxWidgets for this platform in Windows yet (read <a href="http://wiki.wxwidgets.org/Supporting_x64_and_Win32_within_one_solution">this</a>).

The source package for the wxWidgets library (named "wxALL" or "wxMSW", currently version 2.8.11) must be downloaded from <a href="http://www.wxwidgets.org/downloads/">here</a> and decompressed in a directory where CMake can find it (e.g. C:\wxWidgets).

In Windows <b>you'll have to manually modify the flag to compile the OpenGL support</b> of wxWidgets. This is achieved by setting <b>wxUSE_GLCANVAS to 1</b> (the default is 0). This is the part of the file <code>wxwidgets\include\wx\msw\setup.h </code> that has to be modified:

<pre class="brush: cpp">// Setting wxUSE_GLCANVAS to 1 enables OpenGL support. You need to have OpenGL
// headers and libraries to be able to compile the library with wxUSE_GLCANVAS
// set to 1. Note that for some compilers (notably Microsoft Visual C++) you
// will need to manually add opengl32.lib and glu32.lib to the list of
// libraries linked with your program if you use OpenGL.
//
// Default is 0.
//
// Recommended setting: 1 if you intend to use OpenGL, 0 otherwise
#define wxUSE_GLCANVAS       1
</pre>

Now, depending on your version of wxWidgets, open the Visual Studio project (may be called <b>wxwidgets\build\msw\wx_dll.dsw</b>).  I recommend to build, with "Build all", <b>only</b> these configurations:

<ul>
<li>DLL Unicode Release  (or just "DLL Release" in wxWidgets &gt;=2.9) </li>
<li>DLL Unicode Debug (or just "DLL Debug" in wxWidgets &gt;=2.9) </li>
</ul>


<br>
<h4 id="OpenCV_Optional_but_strongly_recommended">1.1.3 OpenCV  (Optional, but strongly recommended)</h4>
<br>

It is recommended to compile MRPT against <b>OpenCV 2.0.0</b> (or newer) in order to enjoy the new features such as SURF descriptors. See the instructions in: <a href="http://opencv.willowgarage.com/wiki/InstallGuide">http://opencv.willowgarage.com/wiki/InstallGuide</a>

One interesting option is to compile a SVN snapshot of OpenCV:
Checkout a fresh copy of the development branch by executing: (NOV-2009: OpenCV hosting changed, this is the new SVN uri:)

<pre class="bordered">svn co https://code.ros.org/svn/opencv/trunk/opencv/ opencv
</pre>

or use the graphical program TortoiseSVN.

Then follow the <a href="https://code.ros.org/svn/opencv/trunk/opencv/INSTALL">compiling instructions</a>. 

Once compiled with CMake, running "Configure" in MRPT's CMake project will automatically detect the OpenCV build directory (where you have generated the projects with CMake) and will use it. If it's not detected, set <b>OpenCV_DIR</b> to the build directory of OpenCV.

<br><br>
<h4 id="FFmpeg_for_Win32_Optional_">1.1.4 FFmpeg for Win32 (Optional) </h4>
<br>

The FFmpeg libraries are <b>optional</b>, and they are only needed if you want to use <a href="http://reference.mrpt.org/svn/classmrpt_1_1hwdrivers_1_1_c_f_f_m_p_e_g___input_stream.html">CFFMPEG_InputStream</a>, mainly for supporting IP cameras.

Directly download and decompress anywhere in your disk :
<ul>
<li> <a href="http://ffmpeg.arrozcru.org/builds/shared/ffmpeg-r16537-gpl-lshared-win32.tar.bz2">http://ffmpeg.arrozcru.org/builds/shared/ffmpeg-r16537-gpl-lshared-win32.tar.bz2</a> </li>
<li> or this local copy:  <a href="http://www.mrpt.org/downloads/ffmpeg-r16537-gpl-lshared-win32.tar.bz2">http://www.mrpt.org/downloads/ffmpeg-r16537-gpl-lshared-win32.tar.bz2</a> </li>
<li> or see the "Unofficial win32 builds" web for more recent releases: <a href="http://ffmpeg.arrozcru.org/autobuilds/">http://ffmpeg.arrozcru.org/autobuilds/</a>
</li></ul>

Then when running CMake (cmake-gui), enable <code>MRPT_HAS_FFMPEG_WIN32</code>, press "Configure" and then set <code>FFMPEG_WIN32_ROOT_DIR</code> to the directory where FFmpeg binaries have been uncompressed (e.g. "c:\ffmpeg-r16537-gpl-lshared-win32").

The FFmpeg DLLs will be required at runtime by programs compiled with MRPT under Windows, so make sure the directory <ffmpeg>/bin is in the <b>system PATH</b>.


<br><br>
<h4 id="Code_Laboratories_NUI_SDK_for_Kinect_or_OpenKinect-s_freenect_Optional_only_if_want_to_use_Kinect">1.1.5 Code Laboratories NUI SDK for Kinect <b>or</b> OpenKinect's freenect (Optional, only if want to use Kinect)</h4>
<br>

<small>(For MRPT 0.9.3+ or 0.9.4+, respectively)</small><br><br>

Please, read <a href="http://www.mrpt.org/Kinect_and_MRPT">this page</a> where all the posibilities are explained.


<br><br>
<br><br>
<br>
<br><hr><div style="background-color:#F0F0F0">
<h3 id="On_GNULinux">1.2. On GNU/Linux</h3>
</div><hr>
<div style="float: right;"><img src="./Compiling MRPT_files/icon_linux.png"></div>
<br>


<h4 id="Dependencies">1.2.1. Dependencies</h4>
<br>

These are the recommended libraries (the <b>development</b> packages!) that should exist in your system (see below for short instructions for Ubuntu/Debian/Fedora). Note that <b>all of them are optional, but most of them are really recommended</b>.
<ul>
<li>OpenCV </li>
<li>wxWidgets </li>
<li>ffmpeg libraries (libavcodec, libswscale, etc.) </li>
<li>Freeglut or glut </li>
<li>zlib </li>
<li>libftdi (optional) </li>
<li>libdc1394-22 </li>
<li>libusb-1.0 (This one is for Kinect support in MRPT 0.9.3+)</li>
</ul>


<h4 id="About_OpenCV">1.2.2. About OpenCV</h4>
<br>
You can compile MRPT against OpenCV 1.0.0, 1.1.0 or &gt;=2.0.0, but it won't compile with OpenCV 1.1.0-pre1. 

Install opencv libraries from your repositories or build it manually from SVN HEAD (I prefer this way...), by checking out a fresh copy of the development branch by executing: 

<pre class="bordered">svn co https://code.ros.org/svn/opencv/trunk/opencv/ opencv
</pre>

And follow the compiling instructions.
Under Linux, you'll <b>NOT</b> need to do a "make install" after building OpenCV, since setting the OpenCV_DIR variable in CMake while compiling MRPT is enough.


<br><br>
<h4 id="Ubuntu_Debian"> 1.2.3 Ubuntu, Debian</h4>
<br>
Invoke:
<pre class="bordered"> $ sudo apt-get install build-essential pkg-config cmake \
   libwxgtk2.8-dev libftdi-dev libglut3-dev \
   zlib1g-dev libusb-1.0-0-dev  \
   libdc1394-22-dev libavformat-dev libswscale-dev
</pre>

If you have <b>NOT</b> built OpenCV from sources and want to use the version in the repositories instead, install:
<pre class="bordered"> $ sudo apt-get install libhighgui-dev libcvaux-dev
</pre>

<b>Update Sep/2010:</b> Read <a href="http://www.mrpt.org/node/406">this warning</a> for Ubuntu 10.04.

Note: If the version 2.8 (or newer) of wxWidgets is not available in your distribution, it must be installed manually.

<br><br>
<h4 id="Fedora"> 1.2.4 Fedora</h4>
<br>

Execute:
<pre class="bordered"> $ su -c 'yum install gcc gcc-c++ make cmake wxGTK-devel opencv-devel freeglut-devel'
</pre>

<br>
<h4 id="OpenSUSE"> 1.2.5 OpenSUSE</h4>
<br>

For OpenSUSE 10.X, invoke:
<pre class="bordered"> $ sudo zypper install make gcc gcc-c++ cmake cmake-gui pkg-config \
      zlib-devel wxGTK-devel wxGTK-gl libusb-devel freeglut-devel
</pre>

For OpenSUSE 11.X, invoke:
<pre class="bordered"> $ sudo zypper install make gcc gcc-c++ cmake cmake-gui pkg-config \
      zlib-devel wxGTK-devel wxGTK-gl libusb-devel freeglut-devel 
</pre>



<br><br><br>
<br>
<br><hr><div style="background-color:#F0F0F0">
<h3 id="On_Mac">1.3. On Mac</h3>
</div><hr>

<div style="float: right;"><img src="./Compiling MRPT_files/icon_macos.jpg"></div>
<br>

Building under MacOS is not yet working 100%. Instructions will be given when we solve all the problems.


<br><br>
<br>

<br><hr><div style="background-color:#C0C0C0">
<h2 id="CMake_build_options">2. CMake build options</h2>
</div><hr>

<br><h3 id="Using_cmake-gui">2.1. Using cmake-gui</h3>
<br>

Open cmake-gui (Available for Windows/Linux) and set the "source dir" to the root directory of the MRPT source package you have downloaded. 
Set the "binary directory" to a <b>new, empty</b> directory where to generate the project files. 

Press "configure", check for errors, tune the options as required (read below for a description of some options) and finally click "Generate".


<br><br>

<br><h3 id="Using_cmake_from_the_console">2.2. Using cmake from the console</h3>

This choice is available for Windows/Linux/MacOS.

Go to a  <b>new, empty</b> directory where to generate the project/Makefiles files and run:

<pre class="bordered">$ cmake /home/.../MRPT
</pre>

Replace "/home/.../MRPT" with your actual path to the MRPT source package you have just downloaded. 

This will use all the default options. To tune them, invoke (available for Linux/MacOS):

<pre class="bordered">$ ccmake .
</pre>

<div align="center">
<a href="http://www.mrpt.org/sites/default/files/images/screenshot_cmake_console_linux.jpg">
<img width="250" src="./Compiling MRPT_files/screenshot_cmake_console_linux.preview.jpg">
</a>
<small>(Click the image to see it at full size)</small>
</div>


<br><h3 id="Interesting_build_options">2.3. Interesting build options</h3>

<b>For all platforms/compilers:</b>
<ul>

<li><code>BUILD_APPLICATIONS </code> : By default ON, if unchecked the applications won't be built. Useful if you only want to build MRPT libraries. Notice that you can also always use the <code>MRPT_BUILD_DIR/libs/MRPT_ALL_LIB.*</code> solution (or Makefile) to achieve the same. </li>


<li><code>BUILD_ARIA </code> : Whether to build or not the embedded ARIA library for interfacing Activemedia Robots. Default is ON. Disable it to save build time if you don't plan to use those robots.</li>

<li><code>BUILD_xSENS </code> : Whether to use the CMT library for interfacing xSens inertial sensors. Default is ON.</li>

<li><code> BUILD_EXAMPLES </code> : Whether you want to compile all the examples in the "/samples" directory. Default is OFF.</li>

<li><code>BUILD_KINECT </code> : By default ON. Uncheck if you don't have the required dependencies (read above for your OS). </li>

<li><code> BUILD_SHARED_LIBS </code> : Build static libraries if set to OFF, or dynamic libraries (.so/.dll) otherwise. Default is ON, and it's <b>strongly recommended to always use shared libs</b> unless you have special need for static ones.</li>

<li><code>EIGEN_USE_EMBEDDED_VERSION </code> : By default ON, instructs MRPT to use the Eigen headers in <code>MRPT/otherlibs/eigen3/</code>. Uncheck if you have Eigen installed in the system and it's visible through pkg-config. It's recommended to uncheck this option if you have eigen3 installed in your system (today, eigen3 it's not yet in any distro repository, that's why it's ON by default).</li>

<li><code>MRPT_ALWAYS_CHECKS_DEBUG </code> : If set to ON, additional security checks will be performed at run-time in many classes. Default is OFF. </li>

<li><code>MRPT_ALWAYS_CHECKS_DEBUG_MATRICES </code> : If set to ON, additional security checks will be performed at run-time in several Matrix operations. Default is ON.</li>

<li><code>MRPT_BACKCOMPATIB_08X</code>: Enable backward compatibility #define's and typedef's so code compiling with MRPT 0.8.X can continue working without problems. Enabled by default. If you start a new project, it may be a good idea to disable it so your new code only uses the more modern MRPT names.</li>

<li><code>MRPT_ENABLE_EMBEDDED_ENABLED_PROFILER </code> : If enabled, all code blocks within macros "MRPT_BEGIN/MRPT_END" will be profiled and the statistics dumped to the console at the end of execution of any program. Default is OFF.</li>

<li><code>MRPT_HAS_ASIAN_FONTS </code> : Enables Asian fonts in mrpt::utils::CCanvas (see <a href="http://www.mrpt.org/Implemented_2D_Fonts">this page</a>), but increases library size by 1.5Mb. Default is ON.</li>

<li><code>MRPT_HAS_SVS</code> : To enable integration of the Videre SVS libraries to interface their stereo cameras. You'll need the vendor libraries installed in the system before to enable this option. After setting this option to "ON", the new configuration fields "SVS_ROOT_DIR" will appear and will be tried to be set pointing to the directory where the library is (As of Aug/2010, this option only works in GNU/Linux).</li>

<li><code>MRPT_OCCUPANCY_GRID_CELLSIZE </code> : Can be either 8 or 16 (bits). The size of each cell in the class mrpt::slam::COccupancyGridMap2D. Default is 8 bits. More on this <a href="http://www.mrpt.org/Occupancy_Grids">here</a>.</li>

<li><code>USER_EXTRA_CPP_FLAGS </code> : You can add here whatever additional flags to be passed to the compiler.</li>
</ul>

<br>

<b>For Windows only:</b>
<ul>

<li><code>MRPT_HAS_FFMPEG_WIN32</code> : Enable this and (after running "Configure") then set FFMPEG_WIN32_ROOT_DIR to the directory where FFmpeg binaries have been uncompressed (e.g. "c:\ffmpeg-r16537-gpl-lshared-win32").</li>

<li><code>MRPT_HAS_BUMBLEBEE </code> : To enable integration of the Bumblebee stereo camera SDK. You'll need the vendor provided "Triclops" and "Digiclops" libraries. After setting this option to "ON", the new configuration fields "BUMBLEBEE_DIGICLOPS_ROOT_DIR" and "BUMBLEBEE_TRICLOPS_ROOT_DIR" will appear where the correct corresponding paths must be entered.</li>

</ul>

<br>


<b>For GNU GCC compiler only:</b>
<ul>
<li><code>MRPT_ENABLE_LIBSTD_PARALLEL_MODE</code> : Enables the GNU libstdc++ parallel mode (See http://gcc.gnu.org/onlinedocs/libstdc++/manual/parallel_mode.html). Default is OFF.</li>

<li><code>MRPT_ENABLE_PROFILING</code> : Enables generation of information required for profiling. Default is OFF.</li>

<li><code>MRPT_OPTIMIZE_NATIVE</code> : Enables optimization for the current architecture (-mtune=native). Default is OFF for old GCC versions, ON for 4.2+. If you have an old version of GCC (&lt;4.2), this option cannot be set since it's not recognized by the compiler. Instead, set USER_EXTRA_CPP_FLAGS to the optimization flags for your platform, for example: -march=pentium4.</li>

</ul>


<br>

<br><hr><div style="background-color:#C0C0C0">
<h2 id="Generate_MakefilesIDE_Projects">3. Generate Makefiles/IDE Projects</h2>
</div><hr>

Just select your preferred Makefile/IDE system with CMake. Supported targets are 32/64 bit Visual Studio projects, Unix Makefiles, Codeblocks projects with MinGW, MinGW Makefiles, etc...


<br><br>

<br><hr><div style="background-color:#C0C0C0">
<h2 id="Compile">4. Compile</h2>
</div><hr>

Just build as usual: from Visual Studio click on "Build all" for the targets you want to build (Debug or Release), for Unix Makefiles invoke: 

<pre class="bordered">$ make -j2
</pre>

After building everything, it's a good idea to run the tests by building the "test" target under Visual Studio or by "make test" in Unix/MacOS.

<br>

<br>
<br><hr><div style="background-color:#C0C0C0">
<h2 id="Special_instructions_for_MinGW">5. Special instructions for MinGW</h2>
</div><hr>

<ul>

<li>Install MinGW: Recommended: <a href="http://tdm-gcc.tdragon.net/" target="_blank">http://tdm-gcc.tdragon.net/</a> </li>

<li>Before compiling MRPT with MinGW, it's strongly recommended to compile wxWidgets and OpenCV with MinGW:</li>
<li>Build wxWidgets. Open a command prompt and go to the directory build/msw. Then execute the following commands to rebuild the Release and Debug configurations (as shared libs), so CMake can correctly detect wxWidgets:
<pre class="bordered">mingw32-make -f makefile.gcc SHARED=1 USE_OPENGL=1 BUILD=release 
mingw32-make -f makefile.gcc SHARED=1 USE_OPENGL=1 BUILD=debug 
</pre>
As usual with <code>make</code>, add a <code>-j4</code> if you have a DualCore, etc... to compile faster in parallel.
</li>

<li>Build OpenCV. Use its CMake build system, select the MinGW compiler and follow the generic OpenCV compilation instructions.</li>

<li>Open cmake-gui and select the source directory and an empty target (binary) directory.</li>

<li>Press configure and in the compilers dialog pick MinGW Makefiles. If you obtain an error like:
<pre>CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  
CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
</pre>
it means MinGW is not correctly installed in the system. Review the installation process described above.</li>

<li>If everything goes fine, you'll see the new CMake variables remarked in red. Go through the normal configuration process for MRPT, and when you are satisfied, press Generate.</li>

<li>Open a console and in the newly created binary directory, invoke:
<pre>mingw32-make
</pre>
either by writing the full path (e.g. c:\MinGW\bin\mingw32-make) or by adding the "bin" directory of your MinGW installation to the system PATH. This should start the normal build process.</li>

</ul></ffmpeg>  </div>
    </div></div></div>
  

</body></html>